package org.example.servlet;

import org.example.service.BookService;
import org.example.service.MessageService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

@WebServlet(name = "InsertMessageServlet", urlPatterns = "/Message/Insert")
public class InsertMessageServlet extends HttpServlet {
    private MessageService messageService=new MessageService();


    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req,
                          HttpServletResponse resp) throws ServletException, IOException {
        //1. 取参（req当前的页码, 每页的数量, 搜索）
        String message=req.getParameter("inputtext");


        int insertresult = 0;
       insertresult  = messageService.insertMessage(req.getSession(),message);


        if (insertresult>0) {
            req.getRequestDispatcher("/Message.jsp?message=" + URLEncoder.encode(String.valueOf(insertresult), "utf-8")).forward(req, resp);
        } else {

        }
    }

}
